<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveScaffold::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveScaffold::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/active_scaffold/lib/active_scaffold_rb.html">
                vendor/plugins/active_scaffold/lib/active_scaffold.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000170">active_scaffold</a>&nbsp;&nbsp;
      <a href="#M000171">active_scaffold_config</a>&nbsp;&nbsp;
      <a href="#M000172">active_scaffold_config_for</a>&nbsp;&nbsp;
      <a href="#M000173">active_scaffold_controller_for</a>&nbsp;&nbsp;
      <a href="#M000174">uses_active_scaffold?</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Finder.html">ActiveScaffold::Finder</a></span>
        <span class="include-name"><a href="Constraints.html">ActiveScaffold::Constraints</a></span>
        <span class="include-name"><a href="AttributeParams.html">ActiveScaffold::AttributeParams</a></span>
        <span class="include-name"><a href="Actions/Core.html">ActiveScaffold::Actions::Core</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000170" class="method-detail">
        <a name="M000170"></a>

        <div class="method-heading">
          <a href="#M000170" class="method-signature">
          <span class="method-name">active_scaffold</span><span class="method-args">(model_id = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000170-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000170-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/active_scaffold.rb, line 42</span>
42:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold</span>(<span class="ruby-identifier">model_id</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
43:       <span class="ruby-comment cmt"># initialize bridges here</span>
44:       <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Bridge</span>.<span class="ruby-identifier">run_all</span>
45: 
46:       <span class="ruby-comment cmt"># converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'</span>
47:       <span class="ruby-identifier">model_id</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'::'</span>).<span class="ruby-identifier">last</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/Controller$/</span>, <span class="ruby-value str">''</span>).<span class="ruby-identifier">pluralize</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">underscore</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">model_id</span>
48: 
49:       <span class="ruby-comment cmt"># run the configuration</span>
50:       <span class="ruby-ivar">@active_scaffold_config</span> = <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span><span class="ruby-operator">::</span><span class="ruby-constant">Core</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">model_id</span>)
51:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">configure</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
52:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">_load_action_columns</span>
53: 
54:       <span class="ruby-comment cmt"># defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead</span>
55:       <span class="ruby-identifier">klass</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>
56:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:generated_methods?</span>
57:         <span class="ruby-comment cmt"># edge rails (2.0)</span>
58:         <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">define_attribute_methods</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">generated_methods?</span>
59:       <span class="ruby-keyword kw">else</span>
60:         <span class="ruby-comment cmt"># stable rails (1.2.3)</span>
61:         <span class="ruby-comment cmt"># NOTE define_read_methods is an *instance* method even though it adds methods to the *class*.</span>
62:         <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:define_read_methods</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">read_methods</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">generate_read_methods</span>
63:       <span class="ruby-keyword kw">end</span>
64: 
65:       <span class="ruby-comment cmt"># set up the generic_view_paths (Rails 2.x)</span>
66:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">method_defined?</span> <span class="ruby-identifier">:generic_view_paths</span>
67:         <span class="ruby-identifier">frontends_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">RAILS_ROOT</span>, <span class="ruby-value str">'vendor'</span>, <span class="ruby-value str">'plugins'</span>, <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span><span class="ruby-operator">::</span><span class="ruby-constant">Core</span>.<span class="ruby-identifier">plugin_directory</span>, <span class="ruby-value str">'frontends'</span>)
68: 
69:         <span class="ruby-identifier">paths</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">inherited_view_paths</span>.<span class="ruby-identifier">clone</span> 
70:         <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">view_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">dir</span><span class="ruby-operator">|</span>
71:           <span class="ruby-identifier">paths</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">dir</span>,<span class="ruby-value str">&quot;active_scaffold_overrides&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">dir</span>,<span class="ruby-value str">&quot;active_scaffold_overrides&quot;</span>))
72:         <span class="ruby-keyword kw">end</span>
73:         <span class="ruby-identifier">paths</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">frontends_path</span>, <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">frontend</span>, <span class="ruby-value str">'views'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">frontend</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">:default</span>
74:         <span class="ruby-identifier">paths</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">frontends_path</span>, <span class="ruby-value str">'default'</span>, <span class="ruby-value str">'views'</span>)
75:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">generic_view_paths</span> = <span class="ruby-identifier">paths</span>
76:       <span class="ruby-keyword kw">end</span>
77: 
78:       <span class="ruby-comment cmt"># include the rest of the code into the controller: the action core and the included actions</span>
79:       <span class="ruby-identifier">module_eval</span> <span class="ruby-keyword kw">do</span>
80:         <span class="ruby-identifier">include</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Finder</span>
81:         <span class="ruby-identifier">include</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Constraints</span>
82:         <span class="ruby-identifier">include</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">AttributeParams</span>
83:         <span class="ruby-identifier">include</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Actions</span><span class="ruby-operator">::</span><span class="ruby-constant">Core</span>
84:         <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">actions</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mod</span><span class="ruby-operator">|</span>
85:           <span class="ruby-identifier">name</span> = <span class="ruby-identifier">mod</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">camelize</span>
86:           <span class="ruby-identifier">include</span> <span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;ActiveScaffold::Actions::#{name}&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Actions</span>.<span class="ruby-identifier">const_defined?</span> <span class="ruby-identifier">name</span>
87: 
88:           <span class="ruby-comment cmt"># sneak the action links from the actions into the main set</span>
89:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">link</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">mod</span>).<span class="ruby-identifier">link</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
90:             <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">action_links</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">link</span>
91:           <span class="ruby-keyword kw">end</span>
92:         <span class="ruby-keyword kw">end</span>
93:       <span class="ruby-keyword kw">end</span>
94:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000171" class="method-detail">
        <a name="M000171"></a>

        <div class="method-heading">
          <a href="#M000171" class="method-signature">
          <span class="method-name">active_scaffold_config</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000171-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000171-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/active_scaffold.rb, line 96</span>
96:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold_config</span>
97:        <span class="ruby-ivar">@active_scaffold_config</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">'@active_scaffold_config'</span>)
98:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000172" class="method-detail">
        <a name="M000172"></a>

        <div class="method-heading">
          <a href="#M000172" class="method-signature">
          <span class="method-name">active_scaffold_config_for</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000172-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000172-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/active_scaffold.rb, line 100</span>
100:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold_config_for</span>(<span class="ruby-identifier">klass</span>)
101:       <span class="ruby-keyword kw">begin</span>
102:         <span class="ruby-identifier">controller</span> = <span class="ruby-identifier">active_scaffold_controller_for</span>(<span class="ruby-identifier">klass</span>)
103:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">ControllerNotFound</span>
104:         <span class="ruby-identifier">config</span> = <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span><span class="ruby-operator">::</span><span class="ruby-constant">Core</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">klass</span>)
105:         <span class="ruby-identifier">config</span>.<span class="ruby-identifier">_load_action_columns</span>
106:         <span class="ruby-identifier">config</span>
107:       <span class="ruby-keyword kw">else</span>
108:         <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">active_scaffold_config</span>
109:       <span class="ruby-keyword kw">end</span>
110:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000173" class="method-detail">
        <a name="M000173"></a>

        <div class="method-heading">
          <a href="#M000173" class="method-signature">
          <span class="method-name">active_scaffold_controller_for</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Tries to find a controller for the given <a
href="../ActiveRecord.html">ActiveRecord</a> model. Searches in the
namespace of the current controller for singular and plural versions of the
conventional &quot;#{model}Controller&quot; syntax. You may override this
method to customize the search routine.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000173-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000173-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/active_scaffold.rb, line 115</span>
115:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold_controller_for</span>(<span class="ruby-identifier">klass</span>)
116:       <span class="ruby-identifier">namespace</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'::'</span>)[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">'::'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">'::'</span>
117:       <span class="ruby-identifier">error_message</span> = []
118:       [<span class="ruby-node">&quot;#{klass.to_s.underscore.pluralize}&quot;</span>, <span class="ruby-node">&quot;#{klass.to_s.underscore.pluralize.singularize}&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">controller_name</span><span class="ruby-operator">|</span>
119:         <span class="ruby-keyword kw">begin</span>
120:           <span class="ruby-identifier">controller</span> = <span class="ruby-node">&quot;#{namespace}#{controller_name.camelize}Controller&quot;</span>.<span class="ruby-identifier">constantize</span>
121:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">error</span>
122:           <span class="ruby-comment cmt"># Only rescue NameError associated with the controller constant not existing - not other compile errors</span>
123:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">error</span>.<span class="ruby-identifier">message</span>[<span class="ruby-node">&quot;uninitialized constant #{controller}&quot;</span>]
124:             <span class="ruby-identifier">error_message</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{namespace}#{controller_name.camelize}Controller&quot;</span>
125:             <span class="ruby-keyword kw">next</span>
126:           <span class="ruby-keyword kw">else</span>
127:             <span class="ruby-identifier">raise</span>
128:           <span class="ruby-keyword kw">end</span>
129:         <span class="ruby-keyword kw">end</span>
130:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">ControllerNotFound</span>, <span class="ruby-node">&quot;#{controller} missing ActiveScaffold&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">uses_active_scaffold?</span>
131:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">ControllerNotFound</span>, <span class="ruby-node">&quot;ActiveScaffold on #{controller} is not for #{klass} model.&quot;</span>, <span class="ruby-identifier">caller</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">klass</span>
132:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">controller</span>
133:       <span class="ruby-keyword kw">end</span>
134:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">ControllerNotFound</span>, <span class="ruby-value str">&quot;Could not find &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">error_message</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot; or &quot;</span>), <span class="ruby-identifier">caller</span>
135:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000174" class="method-detail">
        <a name="M000174"></a>

        <div class="method-heading">
          <a href="#M000174" class="method-signature">
          <span class="method-name">uses_active_scaffold?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000174-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000174-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/active_scaffold.rb, line 137</span>
137:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uses_active_scaffold?</span>
138:       <span class="ruby-operator">!</span><span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">nil?</span>
139:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>